<template>
  <div>
    <!-- 导航区域 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/welcome' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>图书管理</el-breadcrumb-item>
      <el-breadcrumb-item>借阅列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片区域 -->
    <el-card class="box-card">
      <el-row :gutter="20">
        <el-col :span="12">
          <el-input
            placeholder="请输入要借阅人或发布人"
            v-model="book_name"
            clearable
            @clear="getBorrowByPerson"
            @keyup.enter.native="getBorrowByPerson"
          >
            <el-button
              slot="append"
              icon="el-icon-search"
              @click="getBorrowByPerson"
            ></el-button></el-input
        ></el-col>
      </el-row>
      <el-table :data="borrowList" border stripe>
        <el-table-column type="index"></el-table-column>
        <el-table-column prop="image" label="封面">
          <template slot-scope="scope">
            <el-popover placement="top-start" title="" trigger="hover">
              <img
                :src="scope.row.image"
                alt=""
                style="width: 150px; height: 150px"
              />
              <img
                slot="reference"
                :src="scope.row.image"
                style="width: 50px; height: 50px"
              />
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column prop="book_name" label="书名"></el-table-column>
        <el-table-column prop="author" label="作者"></el-table-column>
        <el-table-column prop="borrower" label="借阅人"></el-table-column>
        <el-table-column prop="owner" label="发布人"></el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      borrowList: [],
      book_name: "",
    };
  },
  created() {
    this.getBorrowsList();
  },
  methods: {
    async getBorrowsList() {
      let res = await this.$http.get("book/borrowAll");
      if (res.data.status !== 200) {
        return this.$message.error(res.data.message);
      }
      this.borrowList = res.data.borrowList.map((item) => {
        let { image, book_name, author } = item.book;
        return { ...item, image, book_name, author };
      });
      //   this.$message.success(res.data.message);
    },
    //搜索功能
    async getBorrowByPerson() {
      let keyValue = this.book_name;
      let res = await this.$http.post("book/borrow/search", {
        keyValue,
      });
      if (res.data.status !== 200) {
        return this.$message.error(res.data.message);
      }
      this.borrowList = res.data.borrowList.map((item) => {
        let { image, book_name, author } = item.book;
        return { ...item, image, book_name, author };
      });
      this.$message.success(res.data.message);
    },
  },
};
</script>

<style lang="less" scope>
.el-tag {
  margin-top: 15px;
}
.bt {
  border-top: 1px solid #eee;
}
.bb {
  border-bottom: 1px solid #eee;
}
.vercenter {
  display: flex;
  align-items: center;
}
</style>